﻿using BGSEOTools.WebApp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BGSEOTools.WebApp.Controllers
{
    public class IpDnsController : Controller
    {
        private const string ForwardedFor = "X-Forwarded-For";

        public ActionResult MyIpAddress()
        {
            string ipAddress = string.Empty;
            if (!string.IsNullOrEmpty(Request.Headers[ForwardedFor]))
            {
                ipAddress = Request.Headers[ForwardedFor];
            }
            else if (!string.IsNullOrEmpty(HttpContext.Request.UserHostAddress))
            {
                ipAddress = HttpContext.Request.UserHostAddress;
            }

            var model = new IpAddressModel()
            {
                IpAddress = ipAddress
            };

            return View(model);
        }
    }
}